package util

//borrows heavily from vitess' implementation

import (
	"container/list"
	"sync"
	"time"
)

type LRUCache struct {
	sync.Mutex

	list  *list.List
	table map[string]*list.Element

	//size and capx both in #element
	size uint32
	capx uint32
}

type cacheEntry struct {
	key      string
	value    interface{}
	accessed time.Time
}

func NewLRUCache(capx uint32) *LRUCache {
	return &LRUCache{
		list:  list.New(),
		table: make(map[string]*list.Element),
		capx:  capx,
	}
}

func (lc *LRUCache) Clear() {
	lc.Lock()
	defer lc.Unlock()

	lc.list.Init()
	lc.table = make(map[string]*list.Element)
	lc.size = 0
}

func (lc *LRUCache) SetCapx(capx uint32) {
	lc.Lock()
	defer lc.Unlock()

	lc.capx = capx
	lc.reclaim()
}

func (lc *LRUCache) Set(key string, value interface{}, onlyAbsent bool) (absent bool) {
	lc.Lock()
	defer lc.Unlock()

	return
}

func (lc *LRUCache) Get(key string) (value interface{}, ok bool) {
	lc.Lock()
	defer lc.Unlock()

	return
}

func (lc *LRUCache) Delete(key string) bool {
	lc.Lock()
	defer lc.Unlock()

	return true
}

func (lc *LRUCache) Stats() (size, capx uint32, oldest time.Time) {
	lc.Lock()
	defer lc.Unlock()

	return
}

func (lc *LRUCache) reclaim() {
	for lc.capx < lc.size {

	}
}
